package com.poetic.network.flow.function;

import com.poetic.network.flow.domain.UrlViewCount;
import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

/**
 * <pre>
 *  TODO
 * Created by lianghuikun on 2020-09-15.
 * </pre>
 *
 * @author lianghuikun
 */
public class WindowResultFunction implements WindowFunction<Long, UrlViewCount, String, TimeWindow> {
    @Override
    public void apply(String key, TimeWindow window, Iterable<Long> input, Collector<UrlViewCount> out) throws Exception {
        UrlViewCount view = UrlViewCount.builder()
                .url(key)
                .windowEnd(window.getEnd())
                .count(input.iterator().next())
                .build();

        out.collect(view);
    }
}
